package com.mooc.yohoshop.ui.order;

import com.google.gson.Gson;
import com.mooc.yohoshop.ApiService;
import com.mooc.yohoshop.entity.BaseEntity;
import com.mooc.yohoshop.entity.OrderEntity;
import com.mooc.yohoshop.network.BaseRepository;
import com.mooc.yohoshop.network.HttpFactory;
import com.mooc.yohoshop.network.HttpType;

import java.util.HashMap;

import io.reactivex.Observable;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class OrderRepo extends BaseRepository {

    //获取订单列表
    Observable<BaseEntity>requestOrderList(HashMap<String,Object>map){
        return convertObservable(HttpFactory.factory(HttpType.UPLOADTYPE)
                .getRetrofit().create(ApiService.class).requestOrderList(createBody(map)));
    }
    //删除订单
    Observable<BaseEntity>requestDelOrder(HashMap<String,Object>map){
        return convertObservable(HttpFactory.factory(HttpType.UPLOADTYPE).getRetrofit().create(ApiService.class)
                .requestDelOrder(createBody(map)));
    }
    //修改订单
    Observable<BaseEntity>requestUpdateOrder( OrderEntity.OrderGoodsValues entity){
        return convertObservable(HttpFactory.factory(HttpType.UPLOADTYPE).getRetrofit().create(ApiService.class)
                .requestUpdateOrder( RequestBody.create(MediaType.parse("application/json"),
                        new Gson().toJson(entity))));
    }
}
